#
# ReDefine configuration
#

# [ReDefine]
#
# HeadersDir = <path>
# ScriptsDir = <path>
#
[ReDefine]
HeadersDir            = ../../Fallout2/Fallout1in2/Mapper/source/scripts/headers
ScriptsDir            = ../../Fallout2/Fallout1in2/Mapper/source/scripts
FormatFunctions       = 2
FormatFunctionsForced = true

# [Defines]
# Assigns names to defines types
#
# <type> = <path> <prefix> (group)
#
#   type     name for given value type
#   path     path to file containing interesting defines (relative to [ReDefine]->ScriptsDir)
#   prefix   required prefix for interesting defines
#   group    optional; allows to group multiple types under single name
#
[Defines]
AI = aipacket.h AI
ANIM = animcomd.h ANIM
AREA = maps.h AREA
BACKGROUND = define.h BACKGROUND
CRITTER_PID = critpid.h PID - ANY_PID
DAM = define.h DAM
DMG = define.h DMG
ELEV = define.h ELEV
FID = artfid.h FID
FLOAT_MSG = define.h FLOAT_MSG
GENDER = define.h GENDER
GVAR = global.h GVAR
HEAD = define.h HEAD
INVEN_TYPE = define.h INVEN_TYPE
ITEM_DATA = define.h it
ITEM_PID = itempid.h PID - ANY_PID
ITEM_TYPE = define.h item_type
MAP = maps.h MAP
METARULE = define.h METARULE
OBJECT = define.h OBJECT
PCSTAT = define.h PCSTAT
PERK = define.h PERK
PROC = define.h - proc
RB = animcomd.h RB
REACTION = define.h - REACTION
REG_ANIM = animcomd.h REG_ANIM
SCENERY_PID = scenepid.h PID - ANY_PID
SID = scripts.h SCRIPT
SKILL = define.h SKILL
STAT = define.h STAT
TEAM = teams.h TEAM
# needs to be in two separate files, as they share same prefix
TRAIT_TYPE = fo1.h TRAIT
TRAIT = define.h TRAIT

# [Defines:TYPE]
# Creates program-specific defines
#
# <value> = <name>
#

# Special ANIM values
[Defines:ANIM]
1000 = ANIMATE_ROTATION
1010 = ANIMATE_SET_FRAME

[Defines:ANIMATE_SPEED]
0 = ANIMATE_WALK
1 = ANIMATE_RUN

# Do not complain or change SID 0/-1
[Defines:SID]
0 = 0
-1 = -1

# [Variable]
# ???
#
# <name> = <type>
#
#   name   variable name
#   type   name for given value type
#
[Variable]
Critter_script = SID
Critter_type = CRITTER_PID
cur_map_index = MAP
cur_town = AREA
dude_gender = GENDER
script_action = PROC
self_ai = AI
self_gender = GENDER
self_pid = ANY_PID
self_team = TEAM

# [VariableGuess]
#
# VariableGuess = <types list>
#
[VariableGuess]
VariableGuess = SCENERY_PID

# [Function]
# ???
#
# <name> = <types list>
#
#   name         function name
#   types list   aguments types; if given argument shouldn't be checked/changed, use ? or ??? virtual types
#
[Function]
anim = ? ANIM ?
animate_move_obj_to_tile = ? ? ANIMATE_SPEED
art_anim = [ANIM] ?
art_change_fid_num = ? FID
create_object = ANY_PID ? ?
create_object_sid  = ANY_PID ? ? SID
critter_add_trait = ? TRAIT_TYPE ?dynamic? ?dynamic?
critter_injure = ? DAM
critter_inven_obj = ? INVEN_TYPE
critter_inven_obj2 = ? INVEN_TYPE
critter_skill_level = ? SKILL
critter_dmg = ? ? DMG
critter_mod_skill = ? SKILL ?
critter_rm_trait = ? TRAIT_TYPE ?dynamic? ?
do_check = ? STAT ?
dude_item = ITEM_PID
dude_item_count = ITEM_PID
dude_perk = PERK
dude_trait = TRAIT
elevator = ELEV
float_msg = ? ? FLOAT_MSG
get_critter_stat = ? STAT
get_gender = [GENDER] ?
get_item_count = ? ITEM_PID
get_pc_stat = PCSTAT
get_perk = ? PERK
get_trait = ? TRAIT
giq_option = ? SID ? ? REACTION
global_var = GVAR
gsay_message = SID ? REACTION
gsay_option = SID ? ? ?
gsay_reply = SID ?
has_skill = ? SKILL
has_trait = TRAIT_TYPE ? ?dynamic?
is_skill_tagged = SKILL
kill_critter = ? ANIM
kill_critter_type = CRITTER_PID ?
load_map = MAP ?
map_is_known = MAP
message_str = SID ?
metarule = METARULE ?
obj_carrying_pid_obj = ? ITEM_PID
obj_is_carrying_obj_pid = ? ITEM_PID
obj_item_subtype = [ITEM_TYPE] ?
obj_pid = [ANY_PID] ?
reg_anim_animate = ? ANIM ?
reg_anim_func = REG_ANIM ?dynamic?
roll_vs_skill = ? SKILL ?
self_item = ITEM_PID
self_item_count = ITEM_PID
self_perk = PERK
self_trait = TRAIT
set_critter_stat = ? STAT ?
set_ai = ? AI
set_global_var = GVAR ?
set_self_ai = AI
set_self_team = TEAM
set_team = ? TEAM
start_gdialog = ? ? ? ?HEAD? ?BACKGROUND?
tile_contains_pid_obj = ? ? ANY_PID
using_skill = ? SKILL

# [Raw]
# Replaces all occurences of raw text
#
# <from> = <to>
#
#   from   text to search
#   to     replacement
#
[Raw]
SKILL_CONVERSANT = SKILL_SPEECH
STAT_max_hit_points = STAT_max_hp

[Script:Setup:CritterAddTrait]
#
# edited very early due to arguments depending on each other
# standard replacements won't be able to process function properly without this setup
#
AI = RunBefore:3 IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_AI_PACKET DoArgumentSetType:3,AI
Object = RunBefore:1 IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_OBJECT DoArgumentSetType:2,OBJECT
Perk = RunBefore:0 IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_PERK DoArgumentSetType:2,PERK
Team = RunBefore:4 IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_TEAM_NUM DoArgumentSetType:3,TEAM
Trait = RunBefore:2 IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_TRAIT DoArgumentSetType:2,TRAIT

[Script:Setup:CritterRmTrait]
#
# edited very early due to arguments depending on each other
# standard replacements won't be able to process function properly without this setup
#
AI = RunBefore:3 IfFunction:critter_rm_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_AI_PACKET DoArgumentSetType:3,AI
Object = RunBefore:1 IfFunction:critter_rm_trait IfArgumentIs:1,TRAIT_OBJECT DoArgumentSetType:2,OBJECT
Perk = RunBefore:0 IfFunction:critter_rm_trait IfArgumentIs:1,TRAIT_PERK DoArgumentSetType:2,PERK
Team = RunBefore:4 IfFunction:critter_rm_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_TEAM_NUM DoArgumentSetType:3,TEAM
Trait = RunBefore:2 IfFunction:critter_rm_trait IfArgumentIs:1,TRAIT_TRAIT DoArgumentSetType:2,TRAIT

[Script:Setup:GetCritterStat]
Gender = RunBefore:0 IfFunction:get_critter_stat IfArgumentIs:1,STAT_gender DoReturnSetType:GENDER

[Script:Setup:HasTrait]
#
# edited very early due to arguments depending on each other
# standard replacements won't be able to process function properly without this setup
#
Object = RunBefore:1 IfFunction:has_trait IfArgumentIs:0,TRAIT_OBJECT DoArgumentSetType:2,OBJECT
Perk = RunBefore:0 IfFunction:has_trait IfArgumentIs:0,TRAIT_PERK DoArgumentSetType:2,PERK
Trait = RunBefore:2 IfFunction:has_trait IfArgumentIs:0,TRAIT_TRAIT DoArgumentSetType:2,TRAIT

[Script:Setup:StartGDialog]
#
# edited very early due to lack of defines for -1
# could be easily fixed in headers, but it wouldn't work with decompiled scripts
#
Head = RunBefore:1 IfFunction:start_gdialog !IfArgumentValue:3,-1 DoArgumentSetType:3,HEAD
Background = RunBefore:2 IfFunction:start_gdialog !IfArgumentValue:4,-1 DoArgumentSetType:4,BACKGROUND

[Script:Setup:RegAnimFunc]
RegAnimBegin = RunBefore:0 IfFunction:reg_anim_func IfArgumentIs:0,REG_ANIM_BEGIN DoArgumentSetType:1,RB

[Script:Fix:GetGameMode]
ForceBitwiseAnd = RunAfter IfVariable:get_game_mode IfOperatorName:Equals !IfOperatorValue:0 DoOperatorSet:bwand
Report = RunAfter:9999 IfVariable:get_game_mode IfOperatorName:Equals DoLogCurrentLine

[Script:Humanize:Metarule]
#
# edited early, as other parts of config might want to process results
#
SignalEndGame = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_SIGNAL_END_GAME DoVariable:signal_end_game
MapFirstRun = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_TEST_FIRSTRUN DoVariable:map_first_run
Elevator = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_ELEVATOR DoNameSet:elevator DoArgumentsErase:0
PartyMemberCount = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_PARTY_COUNT DoNameSet:party_member_count DoArgumentsErase:0
TownKnown = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_AREA_KNOWN DoNameSet:town_known DoArgumentsErase:0
DrugInfluence = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_WHO_ON_DRUGS DoNameSet:drug_influence DoArgumentsErase:0
MapIsKnown = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_MAP_KNOWN DoNameSet:map_is_known DoArgumentsErase:0
IsLoadingGame = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_IS_LOADGAME DoVariable:is_loading_game
CarCurrentTown = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_CAR_CURRENT_TOWN DoVariable:car_current_town
CarGiveToParty = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_GIVE_CAR_TO_PARTY DoVariable:car_give_to_party
CarGiveGas = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_GIVE_CAR_GAS DoNameSet:car_give_gas DoArgumentsErase:0
IsSkillTagged = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_SKILL_CHECK_TAG DoNameSet:is_skill_tagged DoArgumentsErase:0
ObjDropEverything = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_DROP_ALL_INVEN DoNameSet:obj_drop_everything DoArgumentsErase:0
InvenUnwield = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_INVEN_UNWIELD_WHO DoNameSet:inven_unwield DoArgumentsErase:0
WorldmapXpos = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_GET_WORLDMAP_XPOS DoVariable:worldmap_xpos
WorldmapYpos = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_GET_WORLDMAP_YPOS DoVariable:worldmap_ypos
CurTown = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_CURRENT_TOWN DoVariable:cur_town
LanguageFilterIsOn = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_LANGUAGE_FILTER DoVariable:language_filter_is_on
ViolenceFilterSetting = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_VIOLENCE_FILTER DoVariable:violence_filter_setting
WeaponDmgType = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_W_DAMAGE_TYPE DoNameSet:weapon_dmg_type DoArgumentsErase:0
CritterCanBarter = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_CRITTER_BARTERS DoNameSet:critter_can_barter DoArgumentsErase:0
CritterKillType = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_CRITTER_KILL_TYPE DoNameSet:critter_kill_type DoArgumentsErase:0
SetCarCarryAmount = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_SET_CAR_CARRY_AMOUNT DoNameSet:set_car_carry_amount DoArgumentsErase:0
CarCarryAmount = RunAfter:10 IfFunction:metarule IfArgumentIs:0,METARULE_GET_CAR_CARRY_AMOUNT DoVariable:car_carry_amount

[Script:Humanize:Not]
DudeCaps = RunAfter:50 IfFunction:not IfArgumentsSize:1 IfArgumentValue:0,dude_caps DoVariable:dude_caps DoOperatorSet:==,0
SelfCaps = RunAfter:50 IfFunction:not IfArgumentsSize:1 IfArgumentValue:0,self_caps DoVariable:self_caps DoOperatorSet:==,0

[Script:Humanize:SfallArrays]
#define create_array_list(size)     (create_array(size, 0))
#define temp_array_list(size)       (temp_array(size, 0))
#define create_array_map            (create_array(-1, 0))
#define temp_array_map              (temp_array(-1, 0))
#define create_lookup_map           (create_array(-1, 2))
#define temp_lookup_map             (temp_array(-1, 2))
#define array_is_map(x)             (array_key(x, -1) == 1)
#define list_saved_arrays           (load_array("...all_arrays..."))
#define unsave_array(x)             save_array(0, x)
#define is_in_array(item, array)    (scan_array(array, item) != -1)
#define array_exists(array)         (len_array(array) != -1)
#define clear_array(array)          resize_array(array, 0)
#define sort_array(array)           resize_array(array, -2)
#define sort_array_reverse(array)   resize_array(array, -3)
#define reverse_array(array)        resize_array(array, -4)
#define shuffle_array(array)        resize_array(array, -5)
#define sort_map_value(array)       resize_array(array, -6)
#define sort_map_reverse(array)     resize_array(array, -7)
#define unset_array(array, item)    set_array(array, item, 0)

CreateArrayList = IGNORE IfFunction:create_array TODO:args[0]>=0 IfArgumentValue:1,0 DoNameSet:create_array_list DoArgumentsResize:1
TempArrayList = IGNORE IfFunction:temp_array TODO:args[0]>=0 IfArgumentValue:1,0 DoNameSet:temp_array_list DoArgumentsResize:1
CreateArrayMap = RunAfter IfFunction:create_array IfArgumentValue:0,-1 IfArgumentValue:1,0 DoVariable:create_array_map
TempArrayMap = RunAfter IfFunction:temp_array IfArgumentValue:0,-1 IfArgumentValue:1,0 DoVariable:temp_array_map
CreateLookupMap = RunAfter IfFunction:create_array IfArgumentValue:0,-1 IfArgumentValue:1,2 DoVariable:create_lookup_map
TempLookupMap = RunAfter IfFunction:temp_array IfArgumentValue:0,-1 IfArgumentValue:1,2 DoVariable:temp_lookup_map
ArrayIsMap = RunAfter IfFunction:array_key IfArgumentValue:1,-1 IfOperatorName:Equals IfOperatorValue:1 DoNameSet:array_is_map DoArgumentsResize:1 DoOperatorClear
ListSavedArrays = RunAfter IfFunction:load_array IfArgumentValue:0,"...all_arrays..." DoVariable:list_saved_arrays
UnsaveArray = RunAfter IfFunction:save_array IfArgumentValue:0,0 DoNameSet:unsave_array DoArgumentsErase:0
IsInArray = RunAfter IfFunction:scan_array IfOperatorName:NotEquals IfOperatorValue:-1 DoNameSet:is_in_array DoArgumentsMoveBack:0 DoOperatorClear
ArrayExists = RunAfter IfFunction:len_array IfOperatorName:NotEquals IfOperatorValue:-1 DoNameSet:array_exists DoOperatorClear
ClearArray = RunAfter IfFunction:resize_array IfArgumentValue:1,0 DoNameSet:clear_array DoArgumentsResize:1
SortArray = RunAfter IfFunction:resize_array IfArgumentValue:1,-2 DoNameSet:sort_array DoArgumentsResize:1
SortArrayReverse = RunAfter IfFunction:resize_array IfArgumentValue:1,-3 DoNameSet:sort_array_reverse DoArgumentsResize:1
ReverseArray = RunAfter IfFunction:resize_array IfArgumentValue:1,-4 DoNameSet:reverse_array DoArgumentsResize:1
ShuffleArray = RunAfter IfFunction:resize_array IfArgumentValue:1,-5 DoNameSet:shuffle_array DoArgumentsResize:1
SortMapValue = RunAfter IfFunction:resize_array IfArgumentValue:1,-6 DoNameSet:sort_map_value DoArgumentsResize:1
SortMapReverse = RunAfter IfFunction:resize_array IfArgumentValue:1,-7 DoNameSet:sort_map_reverse DoArgumentsResize:1
UnsetArray = RunAfter IfFunction:set_array IfArgumentValue:2,0 DoNameSet:unset_array DoArgumentsResize:2

[Script:Minimize]
#
# one-liners
#
AttackComplex = RunAfter IfFunction:attack_complex IfArgumentValue:1,0 IfArgumentValue:2,1 IfArgumentValue:3,0 IfArgumentValue:4,0 IfArgumentValue:5,30000 IfArgumentValue:6,0 IfArgumentValue:7,0 DoNameSet:attack DoArgumentsResize:1
CreateObjectSid = RunAfter:50 IfFunction:create_object_sid IfArgumentValue:3,-1 DoNameSet:create_object DoArgumentsResize:3
CritterSkillLevel = RunAfter IfFunction:CRITTER_SKILL_LEVEL,critter_skill_level DoNameSet:has_skill
GSayReply = RunAfter IfFunction:gsay_reply IfArgumentValue:0,NAME DoNameSet:Reply DoArgumentsErase:0
StartDialog = RunAfter IfFunction:start_gdialog IfArgumentValue:0,-1 IfArgumentValue:3,-1 IfArgumentValue:4,-1 DoNameSet:start_dialog DoArgumentsErase:0 DoArgumentsResize:2

[Script:Minimize:Anim]
#
# reverts
#
Revert:AnimateRotation = RunBefore IfFunction:animate_rotation DoNameSet:anim DoArgumentsPushFront:ANIMATE_ROTATION DoArgumentsPushFront:self_obj DoArgumentSetType:1,ANIM
Revert:AnimateSetFrame = RunBefore IfFunction:animate_set_frame DoNameSet:anim DoArgumentsPushFront:ANIMATE_SET_FRAME DoArgumentsPushFront:self_obj DoArgumentSetType:1,ANIM

ObjRotate = RunAfter IfFunction:anim IfArgumentIs:1,ANIMATE_ROTATION DoNameSet:obj_rotate DoArgumentsErase:1
DudeRotate = RunAfter IfFunction:obj_rotate IfArgumentValue:0,dude_obj DoNameSet:dude_rotate DoArgumentsErase:0
SelfRotate = RunAfter IfFunction:obj_rotate IfArgumentValue:0,self_obj DoNameSet:self_rotate DoArgumentsErase:0

DudeLookAtSelf = RunAfter IfFunction:dude_rotate IfArgumentValue:0,dude_rotation_to_self DoVariable:dude_look_at_self
SelfLookAtDude = RunAfter IfFunction:self_rotate IfArgumentValue:0,self_rotation_to_dude DoVariable:self_look_at_dude

DudeSetFrame = RunAfter IfFunction:anim IfArgumentValue:0,dude_obj IfArgumentIs:1,ANIMATE_SET_FRAME DoNameSet:dude_set_frame DoArgumentsMoveFront:2 DoArgumentsResize:1
SelfSetFrame = RunAfter IfFunction:anim IfArgumentValue:0,self_obj IfArgumentIs:1,ANIMATE_SET_FRAME DoNameSet:self_set_frame DoArgumentsMoveFront:2 DoArgumentsResize:1

[Script:Minimize:AnimateMoveObjToTile]
#
# reverts
#
Revert:AnimateMoveToTile = RunBefore IfFunction:animate_move_to_tile DoNameSet:animate_move_obj_to_tile DoArgumentsPushFront:self_obj DoArgumentsPushBack:ANIMATE_WALK DoArgumentSetType:2,ANIMATE_SPEED
Revert:AnimateMoveToTileForce = RunBefore IfFunction:animate_move_to_tile_force DoNameSet:animate_move_obj_to_tile DoArgumentsPushFront:self_obj DoArgumentsPushBack:ANIMATE_RUN_FORCE DoArgumentSetType:2,ANIMATE_SPEED
Revert:AnimateRunToTile = RunBefore IfFunction:animate_run_to_tile DoNameSet:animate_move_obj_to_tile DoArgumentsPushFront:self_obj DoArgumentsPushBack:ANIMATE_RUN DoArgumentSetType:2,ANIMATE_SPEED
Revert:AnimateRunToTileForce = RunBefore IfFunction:animate_run_to_tile_force DoNameSet:animate_move_obj_to_tile DoArgumentsPushFront:self_obj DoArgumentsPushBack:ANIMATE_RUN_FORCE DoArgumentSetType:2,ANIMATE_SPEED
#
# (dude|self)_walk_to_tile(_force)
#
DudeWalkToTile = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,dude_obj IfArgumentIs:2,ANIMATE_WALK DoNameSet:dude_walk_to_tile DoArgumentsErase:2 DoArgumentsErase:0
SelfWalkToTile = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,self_obj IfArgumentIs:2,ANIMATE_WALK DoNameSet:self_walk_to_tile DoArgumentsErase:2 DoArgumentsErase:0

DudeWalkToTileForce = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,dude_obj IfArgumentValue:2,ANIMATE_WALK_FORCE DoNameSet:dude_walk_to_tile_force DoArgumentsErase:2 DoArgumentsErase:0
SelfWalkToTileForce = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,self_obj IfArgumentValue:2,ANIMATE_WALK_FORCE DoNameSet:self_walk_to_tile_force DoArgumentsErase:2 DoArgumentsErase:0

DudeRunToTile = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,dude_obj IfArgumentIs:2,ANIMATE_RUN DoNameSet:dude_run_to_tile DoArgumentsErase:2 DoArgumentsErase:0
SelfRunToTile = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,self_obj IfArgumentIs:2,ANIMATE_RUN DoNameSet:self_run_to_tile DoArgumentsErase:2 DoArgumentsErase:0

DudeRunToTileForce = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,dude_obj IfArgumentValue:2,ANIMATE_RUN_FORCE DoNameSet:dude_run_to_tile_force DoArgumentsErase:2 DoArgumentsErase:0
SelfRunToTileForce = RunAfter IfFunction:animate_move_obj_to_tile IfArgumentValue:0,self_obj IfArgumentValue:2,ANIMATE_RUN_FORCE DoNameSet:self_run_to_tile_force DoArgumentsErase:2 DoArgumentsErase:0

[Script:Minimize:AnimateStandObj]
#Revert:AnimateStand =
#Revert:AnimateStandReverse =

DudeStand = RunAfter IfFunction:animate_stand_obj IfArgumentValue:0,dude_obj DoVariable:dude_stand
SelfStand = RunAfter IfFunction:animate_stand_obj IfArgumentValue:0,self_obj DoVariable:self_stand

DudeStandReverse = RunAfter IfFunction:animate_stand_reverse_obj IfArgumentValue:0,dude_obj DoVariable:dude_stand_reverse
SelfStandReverse = RunAfter IfFunction:animate_stand_reverse_obj IfArgumentValue:0,self_obj DoVariable:self_stand_reverse

[Script:Minimize:ArtAnim]
DudeIsRunning = RunAfter IfFunction:art_anim IfArgumentValue:0,dude_fid IfOperatorName:Equals IfOperatorValue:ANIM_running DoVariable:dude_is_running DoOperatorClear
DudeIsWalking = RunAfter IfFunction:art_anim IfArgumentValue:0,dude_fid IfOperatorName:Equals IfOperatorValue:ANIM_walk DoVariable:dude_is_walking DoOperatorClear
SelfIsRunning = RunAfter IfFunction:art_anim IfArgumentValue:0,self_fid IfOperatorName:Equals IfOperatorValue:ANIM_running DoVariable:self_is_running DoOperatorClear
SelfIsWalking = RunAfter IfFunction:art_anim IfArgumentValue:0,self_fid IfOperatorName:Equals IfOperatorValue:ANIM_walk DoVariable:self_is_walking DoOperatorClear

[Script:Minimize:CritterAddTrait]
#
# set_ai/set_team
#
SetAI   = RunAfter IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_AI_PACKET DoNameSet:set_ai DoArgumentsErase:2 DoArgumentsErase:1
SetTeam = RunAfter IfFunction:critter_add_trait IfArgumentIs:1,TRAIT_OBJECT IfArgumentIs:2,OBJECT_TEAM_NUM DoNameSet:set_team DoArgumentsErase:2 DoArgumentsErase:1
#
# set_self_ai/set_self_team
#
SetSelfAI   = RunAfter IfFunction:set_ai IfArgumentValue:0,self_obj DoNameSet:set_self_ai DoArgumentsErase:0
SetSelfTeam = RunAfter IfFunction:set_team IfArgumentValue:0,self_obj DoNameSet:set_self_team DoArgumentsErase:0

[Script:Minimize:CritterInvenObj]
InvenCount = RunAfter IfFunction:critter_inven_obj IfArgumentIs:1,INVEN_TYPE_INV_COUNT DoNameSet:inven_count DoArgumentsResize:1
#
# get_GEAR
#
# replace critter_inven_obj with sfall's critter_inven_obj2; without it, GetRightHand won't work properly ingame
# GetLeftHand uses *_obj2 for consistency only
GetLeftHandObj2 = RunAfter:50 IfFunction:critter_inven_obj IfArgumentIs:1,INVEN_TYPE_LEFT_HAND DoNameSet:critter_inven_obj2
GetRightHandObj2 = RunAfter:50 IfFunction:critter_inven_obj IfArgumentIs:1,INVEN_TYPE_RIGHT_HAND DoNameSet:critter_inven_obj2
#
GetLeftHand = RunAfter IfFunction:critter_inven_obj2 IfArgumentIs:1,INVEN_TYPE_LEFT_HAND DoNameSet:get_left_hand DoArgumentsResize:1
GetRightHand = RunAfter IfFunction:critter_inven_obj2 IfArgumentIs:1,INVEN_TYPE_RIGHT_HAND DoNameSet:get_right_hand DoArgumentsResize:1
GetArmor = RunAfter IfFunction:critter_inven_obj IfArgumentIs:1,INVEN_TYPE_WORN DoNameSet:get_armor DoArgumentsResize:1
#
# dude_GEAR
#
DudeLeftHand = RunAfter IfFunction:get_left_hand IfArgumentValue:0,dude_obj DoVariable:dude_left_hand DoRestart
DudeRightHand = RunAfter IfFunction:get_right_hand IfArgumentValue:0,dude_obj DoVariable:dude_right_hand DoRestart
DudeArmor = RunAfter IfFunction:get_armor IfArgumentValue:0,dude_obj DoVariable:dude_armor DoRestart
#
# self_GEAR
#
SelfLeftHand = RunAfter IfFunction:get_left_hand IfArgumentValue:0,self_obj DoVariable:self_left_hand DoRestart
SelfRightHand = RunAfter IfFunction:get_right_hand IfArgumentValue:0,self_obj DoVariable:self_right_hand DoRestart
SelfArmor = RunAfter IfFunction:get_armor IfArgumentValue:0,self_obj DoVariable:self_armor DoRestart

[Script:Minimize:CritterState]
IsCritterDead1 = RunAfter IfFunction:critter_state IfOperatorName:BitwiseAnd IfOperatorValue:1 DoNameSet:is_critter_dead DoOperatorClear
IsCritterDead2 = RunAfter IfFunction:critter_state IfOperatorName:BitwiseAnd IfOperatorValue:CRITTER_IS_DEAD DoNameSet:is_critter_dead DoOperatorClear
IsCritterProne1 = RunAfter IfFunction:critter_state IfOperatorName:BitwiseAnd IfOperatorValue:2 DoNameSet:is_critter_prone DoOperatorClear
IsCritterProne2 = RunAfter IfFunction:critter_state IfOperatorName:BitwiseAnd IfOperatorValue:CRITTER_IS_PRONE DoNameSet:is_critter_prone DoOperatorClear

[Script:Minimize:CurX]
CurMapName = RunAfter IfVariable:cur_map_index IfOperatorName:Equals DoOperatorValueCache:map IfReturnType:MAP DoOperatorClear DoNameSetCached:map DoNameSetPrefix:CUR_
CurAreaName = RunAfter IfVariable:cur_town IfOperatorName:Equals DoOperatorValueCache:area IfReturnType:AREA DoOperatorClear DoNameSetCached:area DoNameSetPrefix:CUR_

[Script:Minimize:Elevation]
DudeElevation = RunAfter IfFunction:elevation IfArgumentValue:0,dude_obj DoVariable:dude_elevation DoRestart
SelfElevation = RunAfter IfFunction:elevation IfArgumentValue:0,self_obj DoVariable:self_elevation DoRestart
SourceElevation = RunAfter IfFunction:elevation IfArgumentValue:0,source_obj DoVariable:source_elevation DoRestart

[Script:Minimize:FloatMsg]
FloatMsgClear = RunAfter IfFunction:float_msg IfArgumentValue:1,0 IfArgumentIs:2,FLOAT_MSG_NORMAL DoNameSet:float_msg_clear DoArgumentsResize:1

[Script:Minimize:GetCritterStat]
#
# misc
#
DudeLevel = RunAfter IfFunction:get_critter_stat IfArgumentIs:0,PCSTAT_level DoVariable:dude_level
#
# get_SPECIAL
#
GetStrength   = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_st DoNameSet:get_strength DoArgumentsResize:1
GetPerception = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_pe DoNameSet:get_perception DoArgumentsResize:1
GetEndurance  = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_en DoNameSet:get_endurance DoArgumentsResize:1
GetCharisma   = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_ch DoNameSet:get_charisma DoArgumentsResize:1
GetIQ         = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_iq DoNameSet:get_iq DoArgumentsResize:1
GetAgility    = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_ag DoNameSet:get_agility DoArgumentsResize:1
GetLuck       = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_lu DoNameSet:get_luck DoArgumentsResize:1
#
# get_HP
#
GetCurHp = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_current_hp DoNameSet:get_cur_hp DoArgumentsResize:1
GetMaxHp = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_max_hp DoNameSet:get_max_hp DoArgumentsResize:1
#
# get_rads
#
GetRads = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_current_rad DoNameSet:get_rads DoArgumentsResize:1
DudeRads = RunAfter:90 IfFunction:get_rads IfArgumentValue:0,dude_obj DoVariable:dude_rads
SelfRads = RunAfter:90 IfFunction:get_rads IfArgumentValue:0,self_obj DoVariable:self_rads

#
# get_poison_stat
#
GetPoisonStat = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_current_poison DoNameSet:get_poison_stat DoArgumentsResize:1
DudePoisonStat = RunAfter:90 IfFunction:get_poison_stat IfArgumentValue:0,dude_obj DoVariable:dude_poison_stat
SelfPoisonStat = RunAfter:90 IfFunction:get_poison_stat IfArgumentValue:0,self_obj DoVariable:self_poison_stat

#
# get_GENDER
#
GetGender      = RunAfter:90 IfFunction:get_critter_stat IfArgumentIs:1,STAT_gender DoNameSet:get_gender DoArgumentsResize:1
GetIsMale:EQ   = RunAfter:91 IfFunction:get_gender IfOperatorName:Equals IfOperatorValue:GENDER_MALE DoNameSet:get_is_male DoOperatorClear
GetIsMale:LT   = RunAfter:92 IfFunction:get_gender IfOperatorName:Lower IfOperatorValue:GENDER_FEMALE DoNameSet:get_is_male DoOperatorClear
GetIsMale:NE   = RunAfter:93 IfFunction:get_gender IfOperatorName:NotEquals IfOperatorValue:GENDER_FEMALE DoNameSet:get_is_male DoOperatorClear
GetIsFemale:EQ = RunAfter:91 IfFunction:get_gender IfOperatorName:Equals IfOperatorValue:GENDER_FEMALE DoNameSet:get_is_female DoOperatorClear
GetIsFemale:GT = RunAfter:92 IfFunction:get_gender IfOperatorName:Greater IfOperatorValue:GENDER_MALE DoNameSet:get_is_female DoOperatorClear
GetIsFemale:NE = RunAfter:93 IfFunction:get_gender IfOperatorName:NotEquals IfOperatorValue:GENDER_MALE DoNameSet:get_is_female DoOperatorClear

[Script:Minimize:GetPcStat]
DudeLevel = RunAfter IfFunction:get_pc_stat IfArgumentIs:0,PCSTAT_level DoVariable:dude_level

# prepare converting gsay_option() -> XOption(..., 1), which are supposed to do same thing
[Script:Modernize:GSayOption]
GiqOption = RunAfter:90 IfFunction:gsay_option DoNameSet:giq_option DoArgumentsPushFront:1

[Script:Minimize:GiqOption]
SCRIPT_GENCHAT = RunAfter IfFunction:giq_option IfArgumentIs:1,SCRIPT_GENCHAT DoArgumentSet:1,NAME DoArgumentSetPrefix:2,gen_mstr( DoArgumentSetSuffix:2,)
SCRIPT_GENERIC = RunAfter IfFunction:giq_option IfArgumentIs:1,SCRIPT_GENERIC DoArgumentSet:1,NAME DoArgumentSetPrefix:2,g_mstr( DoArgumentSetSuffix:2,)

SCRIPT_MODREACT:106 = RunAfter IfFunction:giq_option IfArgumentIs:1,SCRIPT_MODREACT IfArgumentValue:2,106 DoArgumentSet:1,NAME DoArgumentSet:2,g_more
SCRIPT_MODREACT:108 = RunAfter IfFunction:giq_option IfArgumentIs:1,SCRIPT_MODREACT IfArgumentValue:2,108 DoArgumentSet:1,NAME DoArgumentSet:2,g_done

GOption  = RunAfter IfFunction:giq_option IfArgumentValue:1,NAME IfArgumentIs:4,GOOD_REACTION DoNameSet:GOption DoArgumentsResize:4 DoArgumentsMoveBack:0 DoArgumentsErase:0
NOption  = RunAfter IfFunction:giq_option IfArgumentValue:1,NAME IfArgumentIs:4,NEUTRAL_REACTION DoNameSet:NOption DoArgumentsResize:4 DoArgumentsMoveBack:0 DoArgumentsErase:0
BOption  = RunAfter IfFunction:giq_option IfArgumentValue:1,NAME IfArgumentIs:4,BAD_REACTION DoNameSet:BOption DoArgumentsResize:4 DoArgumentsMoveBack:0 DoArgumentsErase:0
ROption  = RunAfter IfFunction:giq_option IfArgumentValue:1,NAME IfArgumentValue:4,RND_REACTION DoNameSet:ROption DoArgumentsResize:4 DoArgumentsMoveBack:0 DoArgumentsErase:0
#
GLowOption = RunAfter IfFunction:GOption IfArgumentValue:2,-3 DoNameSet:GLowOption DoArgumentsResize:2
NLowOption = RunAfter IfFunction:NOption IfArgumentValue:2,-3 DoNameSet:NLowOption DoArgumentsResize:2
BLowOption = RunAfter IfFunction:BOption IfArgumentValue:2,-3 DoNameSet:BLowOption DoArgumentsResize:2
RLowOption = RunAfter IfFunction:ROption IfArgumentValue:2,-3 DoNameSet:RLowOption DoArgumentsResize:2

# Force using XOption(..., 1) instead of XOption(..., 0)
Consistency = RunAfter:1000 IfFunction:GOption,NOption,BOption,ROption IfArgumentValue:2,0 DoArgumentSet:2,1

[Script:Minimize:GlobalVar]
#
# misc gl_worldmap.h macros
#
IsTerrainDesert = RunAfter IfFunction:global_var IfArgumentIs:0,GVAR_WORLDMAP_TERRAIN IfOperatorName:Equals IfOperatorValue:WORLDMAP_TERRAIN_DESERT DoVariable:is_terrain_desert
IsTerrainCity = RunAfter IfFunction:global_var IfArgumentIs:0,GVAR_WORLDMAP_TERRAIN IfOperatorName:Equals IfOperatorValue:WORLDMAP_TERRAIN_CITY DoVariable:is_terrain_desert
IsTerrainMountain = RunAfter IfFunction:global_var IfArgumentIs:0,GVAR_WORLDMAP_TERRAIN IfOperatorName:Equals IfOperatorValue:WORLDMAP_TERRAIN_MOUNTAIN DoVariable:is_terrain_mountain
IsTerrainOcean = RunAfter IfFunction:global_var IfArgumentIs:0,GVAR_WORLDMAP_TERRAIN IfOperatorName:Equals IfOperatorValue:WORLDMAP_TERRAIN_OCEAN DoVariable:is_terrain_ocean

[Script:Minimize:GSayMessage]
GMessage = RunAfter IfFunction:gsay_message IfArgumentValue:0,NAME IfArgumentIs:2,GOOD_REACTION DoFunction:GMessage DoArgumentsMoveFront:1 DoArgumentsResize:1
NMessage = RunAfter IfFunction:gsay_message IfArgumentValue:0,NAME IfArgumentIs:2,NEUTRAL_REACTION DoFunction:NMessage DoArgumentsMoveFront:1 DoArgumentsResize:1
BMessage = RunAfter IfFunction:gsay_message IfArgumentValue:0,NAME IfArgumentIs:2,BAD_REACTION DoFunction:BMessage DoArgumentsMoveFront:1 DoArgumentsResize:1

[Script:Minimize:HasTrait]
#
# get_perk/get_trait
#
GetPerk  = RunAfter:90 IfFunction:has_trait IfArgumentIs:0,TRAIT_PERK DoNameSet:get_perk DoArgumentsErase:0
GetTrait = RunAfter:90 IfFunction:has_trait IfArgumentIs:0,TRAIT_TRAIT DoNameSet:get_trait DoArgumentsErase:0
#
# dude_perk/dude_trait
#
DudePerk  = RunAfter:90 IfFunction:get_perk IfArgumentValue:0,dude_obj DoNameSet:dude_perk DoArgumentsErase:0
DudeTrait = RunAfter:90 IfFunction:get_trait IfArgumentIs:0,dude_obj DoNameSet:dude_trait DoArgumentsErase:0
#
# self_perk/self_trait
#
SelfPerk  = RunAfter:90 IfFunction:get_perk IfArgumentValue:0,self_obj DoNameSet:self_perk DoArgumentsErase:0
SelfTrait = RunAfter:90 IfFunction:get_trait IfArgumentIs:0,self_obj DoNameSet:self_trait DoArgumentsErase:0
#
# get_ai/get_team
#
GetAI   = RunAfter IfFunction:has_trait IfArgumentIs:0,TRAIT_OBJECT IfArgumentIs:2,OBJECT_AI_PACKET DoNameSet:get_ai DoArgumentsMoveFront:1 DoArgumentsResize:1
GetTeam = RunAfter IfFunction:has_trait IfArgumentIs:0,TRAIT_OBJECT IfArgumentIs:2,OBJECT_TEAM_NUM DoNameSet:get_team DoArgumentsMoveFront:1 DoArgumentsResize:1
#
# self_ai/self_team
#
SelfAI   = RunAfter IfFunction:get_ai IfArgumentValue:0,self_obj DoVariable:self_ai
SelfTeam = RunAfter IfFunction:get_team IfArgumentValue:0,self_obj DoVariable:self_team
#
# get_cur_rot/dude_cur_rot/self_cur_rot
#
GetCurRot  = RunAfter IfFunction:has_trait IfArgumentIs:0,TRAIT_OBJECT IfArgumentIs:2,OBJECT_CUR_ROT DoNameSet:get_cur_rot DoArgumentsMoveFront:1 DoArgumentsResize:1
DudeCurRot = RunAfter IfFunction:get_cur_rot IfArgumentValue:0,dude_obj DoVariable:dude_cur_rot
SelfCurRot = RunAfter IfFunction:get_cur_rot IfArgumentValue:0,self_obj DoVariable:self_cur_rot
#
# obj_is_visible_flag
#
ObjIsVisibleFlag = RunAfter IfFunction:has_trait IfArgumentIs:0,TRAIT_OBJECT IfArgumentIs:2,OBJECT_VISIBILITY DoNameSet:obj_is_visible_flag DoArgumentsMoveFront:1 DoArgumentsResize:1
IsVisible = RunAfter IfFunction:obj_is_visible_flag DoNameSet:is_visible
SelfVisible = RunAfter IfFunction:is_visible IfArgumentValue:0,self_obj DoVariable:self_visible

[Script:Minimize:ItemCapsAdjust]
DudeCapsAdjust = RunAfter IfFunction:item_caps_adjust IfArgumentValue:0,dude_obj DoNameSet:dude_caps_adjust DoArgumentsErase:0
SelfCapsAdjust = RunAfter IfFunction:item_caps_adjust IfArgumentValue:0,self_obj DoNameSet:self_caps_adjust DoArgumentsErase:0

[Script:Minimize:ItemCapsTotal]
DudeCaps = RunAfter IfFunction:item_caps_total IfArgumentValue:0,dude_obj DoVariable:dude_caps DoRestart
SelfCaps = RunAfter IfFunction:item_caps_total IfArgumentValue:0,self_obj DoVariable:self_caps DoRestart

[Script:Minimize:MessageStr]
Mstr    = RunAfter:105 IfFunction:message_str IfArgumentValue:0,NAME DoNameSet:mstr DoArgumentsErase:0
GMstr   = RunAfter:105 IfFunction:message_str IfArgumentIs:0,SCRIPT_GENERIC DoNameSet:g_mstr DoArgumentsErase:0
GenMstr = RunAfter:105 IfFunction:message_str IfArgumentIs:0,SCRIPT_GENCHAT DoNameSet:gen_mstr DoArgumentsErase:0
GMore   = RunAfter:105 IfFunction:message_str IfArgumentIs:0,SCRIPT_MODREACT IfArgumentValue:1,106 DoVariable:g_more
GDone   = RunAfter:105 IfFunction:message_str IfArgumentIs:0,SCRIPT_MODREACT IfArgumentValue:1,108 DoVariable:g_done

[Script:Minimize:ObjArtFid]
DudeFid = RunAfter IfFunction:obj_art_fid IfArgumentValue:0,dude_obj DoVariable:dude_fid DoRestart
SelfFid = RunAfter IfFunction:obj_art_fid IfArgumentValue:0,self_obj DoVariable:self_fid DoRestart

[Script:Minimize:ObjCanSeeHearObj]
ObjCanSeeObj:EQ1 = RunAfter IfFunction:obj_can_see_obj IfOperatorName:Equals IfOperatorValue:1 DoOperatorClear
ObjCanHearObj:EQ1 = RunAfter IfFunction:obj_can_hear_obj IfOperatorName:Equals IfOperatorValue:1 DoOperatorClear
#
# dude_can_see_self/dude_can_hear_self
#
DudeCanSeeSelf = RunAfter IfFunction:obj_can_see_obj IfArgumentValue:0,dude_obj IfArgumentValue:1,self_obj DoVariable:dude_can_see_self
DudeCanHearSelf = RunAfter IfFunction:obj_can_hear_obj IfArgumentValue:0,dude_obj IfArgumentValue:1,self_obj DoVariable:dude_can_hear_self

#
# self_can_see_dude/self_can_hear_dude
#
SelfCanSeeDude = RunAfter IfFunction:obj_can_see_obj IfArgumentValue:0,self_obj IfArgumentValue:1,dude_obj DoVariable:self_can_see_dude
SelfCanHearDude = RunAfter IfFunction:obj_can_hear_obj IfArgumentValue:0,self_obj IfArgumentValue:1,dude_obj DoVariable:self_can_hear_dude
SelfCanSeeDude:EQ1 = RunAfter IfVariable:self_can_see_dude IfOperatorName:Equals IfOperatorValue:1 DoOperatorClear
SelfCanHearDude:EQ1 = RunAfter IfVariable:self_can_hear_dude IfOperatorName:Equals IfOperatorValue:1 DoOperatorClear

[Script:Minimize:ObjCarrying]
#
# get_item/get_item_count
#
GetItem      = RunAfter:90 IfFunction:obj_carrying_pid_obj DoNameSet:get_item
GetItemCount = RunAfter:90 IfFunction:obj_is_carrying_obj_pid DoNameSet:get_item_count
#
# get_item_count(cr,PID_BOTTLE_CAPS) -> item_caps_total(cr)
#
ItemCapsTotal = RunAfter:90 IfFunction:get_item_count IfArgumentIs:1,PID_BOTTLE_CAPS DoNameSet:item_caps_total DoArgumentsResize:1
#
# dude_item/dude_item_count
#
DudeItem      = RunAfter:90 IfFunction:get_item IfArgumentValue:0,dude_obj DoNameSet:dude_item DoArgumentsErase:0
DudeItemCount = RunAfter:90 IfFunction:get_item_count IfArgumentValue:0,dude_obj DoNameSet:dude_item_count DoArgumentsErase:0
#
# self_item/self_item_count
#
SelfItem      = RunAfter:90 IfFunction:get_item IfArgumentValue:0,self_obj DoNameSet:self_item DoArgumentsErase:0
SelfItemCount = RunAfter:90 IfFunction:get_item_count IfArgumentValue:0,self_obj DoNameSet:self_item_count DoArgumentsErase:0
#
# revert (dude|self)_item_count( PID_BOTTLE_CAPS ) -> item_caps_total
#
Revert:DudeItemCountCaps = RunAfter:95 IfFunction:dude_item_count IfArgumentIs:0,PID_BOTTLE_CAPS DoNameSet:item_caps_total DoArgumentsPushFront:dude_obj
Revert:SelfItemCountCaps = RunAfter:95 IfFunction:self_item_count IfArgumentIs:0,PID_BOTTLE_CAPS DoNameSet:item_caps_total DoArgumentsPushFront:self_obj

[Script:Minimize:ObjName]
#
# dude_name/self_name
#
DudeName = RunAfter IfFunction:obj_name IfArgumentValue:0,dude_obj DoVariable:dude_name
SelfName = RunAfter IfFunction:obj_name IfArgumentValue:0,self_obj DoVariable:self_name

[Script:Minimize:ObjPid]
SelfPid = RunAfter IfFunction:obj_pid IfArgumentValue:0,self_obj DoVariable:self_pid DoRestart

[Script:Minimize:RegAnimFunc]
RegAnimBegin = RunAfter IfFunction:reg_anim_func IfArgumentIs:0,REG_ANIM_BEGIN IfArgumentIs:1,RB_UNRESERVED DoNameSet:reg_anim_begin DoArgumentsClear
RegAnimClear = RunAfter IfFunction:reg_anim_func IfArgumentIs:0,REG_ANIM_CLEAR DoNameSet:reg_anim_clear DoArgumentsErase:0
RegAnimEnd = RunAfter IfFunction:reg_anim_func IfArgumentIs:0,REG_ANIM_END IfArgumentValue:1,0 DoNameSet:reg_anim_end DoArgumentsClear
FIX = RunAfter IfFunction:reg_anim_clear IfArgumentsSize:0 DoNameSet:reg_anim_end

[Script:Minimize:RotationToTile]
DudeRotationToTSelf = RunAfter:90 IfFunction:rotation_to_tile IfArgumentValue:0,dude_tile IfArgumentValue:1,self_tile DoVariable:dude_rotation_to_self DoRestart
SelfRotationToTDude = RunAfter:90 IfFunction:rotation_to_tile IfArgumentValue:0,self_tile IfArgumentValue:1,dude_tile DoVariable:self_rotation_to_dude DoRestart

[Script:Minimize:SetObjVisibility]
SetObjVisible = RunAfter IfFunction:set_obj_visibility IfArgumentValue:1,0 DoNameSet:set_obj_visible DoArgumentsResize:1
SetObjInvisible = RunAfter IfFunction:set_obj_visibility IfArgumentValue:1,1 DoNameSet:set_obj_invisible DoArgumentsResize:1
SetSelfVisible = RunAfter IfFunction:set_obj_visible IfArgumentValue:0,self_obj DoVariable:set_self_visible
SetSelfInvisible = RunAfter IfFunction:set_obj_invisible IfArgumentValue:0,self_obj DoVariable:set_self_invisible

[Script:Minimize:TileNum]
DudeTile = RunAfter IfFunction:tile_num IfArgumentValue:0,dude_obj DoVariable:dude_tile DoRestart
SelfTile = RunAfter IfFunction:tile_num IfArgumentValue:0,self_obj DoVariable:self_tile DoRestart
SourceTile = RunAfter IfFunction:tile_num IfArgumentValue:0,source_obj DoVariable:source_tile DoRestart

[Script:Minimize:UsingSkill]
#
# dude_is_sneaking/self_is_sneaking
#
DudeIsSneaking = RunAfter IfFunction:using_skill IfArgumentValue:0,dude_obj IfArgumentIs:1,SKILL_SNEAK DoVariable:dude_is_sneaking
SelfIsSneaking = RunAfter IfFunction:using_skill IfArgumentValue:0,self_obj IfArgumentIs:1,SKILL_SNEAK DoVariable:self_is_sneaking

###########################################################################

[Script:Minimize:Gender]
#
# dude_GENDER
#
DudeGender = RunAfter IfFunction:get_gender IfArgumentValue:0,dude_obj DoVariable:dude_gender
DudeIsMale = RunAfter IfFunction:get_is_male IfArgumentValue:0,dude_obj DoVariable:dude_is_male
DudeIsFemale = RunAfter IfFunction:get_is_female IfArgumentValue:0,dude_obj DoVariable:dude_is_female
#
# self_GENDER
#
SelfGender = RunAfter IfFunction:get_gender IfArgumentValue:0,self_obj DoVariable:self_gender
SelfIsMale = RunAfter IfFunction:get_is_male IfArgumentValue:0,self_obj DoVariable:self_is_male
SelfIsFemale = RunAfter IfFunction:get_is_female IfArgumentValue:0,self_obj DoVariable:self_is_male

[Script:Minimize:SPECIAL]
#
# dude_SPECIAL
#
DudeStrength   = RunAfter IfFunction:get_strength IfArgumentValue:0,dude_obj DoVariable:dude_strength
DudePerception = RunAfter IfFunction:get_perception IfArgumentValue:0,dude_obj DoVariable:dude_perception
DudeEndurance  = RunAfter IfFunction:get_endurance IfArgumentValue:0,dude_obj DoVariable:dude_endurance
DudeCharisma   = RunAfter IfFunction:get_charisma IfArgumentValue:0,dude_obj DoVariable:dude_charisma
DudeIQ         = RunAfter IfFunction:get_iq IfArgumentValue:0,dude_obj DoVariable:dude_iq
DudeAgility    = RunAfter IfFunction:get_agility IfArgumentValue:0,dude_obj DoVariable:dude_agility
DudeLuck       = RunAfter IfFunction:get_luck IfArgumentValue:0,dude_obj DoVariable:dude_luck
#
# self_SPECIAL
#
SelfStrength   = RunAfter IfFunction:get_strength IfArgumentValue:0,self_obj DoVariable:self_strength
SelfPerception = RunAfter IfFunction:get_perception IfArgumentValue:0,self_obj DoVariable:self_perception
SelfEndurance  = RunAfter IfFunction:get_endurance IfArgumentValue:0,self_obj DoVariable:self_endurance
SelfCharisma   = RunAfter IfFunction:get_charisma IfArgumentValue:0,self_obj DoVariable:self_charisma
SelfIQ         = RunAfter IfFunction:get_iq IfArgumentValue:0,self_obj DoVariable:self_iq
SelfAgility    = RunAfter IfFunction:get_agility IfArgumentValue:0,self_obj DoVariable:self_agility
SelfLuck       = RunAfter IfFunction:get_luck IfArgumentValue:0,self_obj DoVariable:self_luck
#
# extras
#
DudeIsStupid   = RunAfter IfVariable:dude_iq IfOperatorName:LowerEquals IfOperatorValue:3 DoNameSet:dude_is_stupid DoOperatorClear

[Script:Minimize:Gear]
#define dude_wearing_coc_robe	    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_WORN)) == PID_PURPLE_ROBE)
DudeWearingCocRobe = RunAfter IfFunction:obj_pid IfArgumentValue:0,dude_armor IfOperatorName:Equals IfOperatorValue:PID_PURPLE_ROBE DoVariable:dude_wearing_coc_robe DoOperatorClear

[Script:Minimize:HitPoints]
#
# dude_cur_hp/dude_max_hp
#
DudeCurHp = RunAfter IfFunction:get_cur_hp IfArgumentValue:0,dude_obj DoVariable:dude_cur_hp
DudeMaxHp = RunAfter IfFunction:get_max_hp IfArgumentValue:0,dude_obj DoVariable:dude_max_hp
#
# self_cur_hp/self_max_hp
#
SelfCurHp = RunAfter IfFunction:get_cur_hp IfArgumentValue:0,self_obj DoVariable:self_cur_hp
SelfMaxHp = RunAfter IfFunction:get_max_hp IfArgumentValue:0,self_obj DoVariable:self_max_hp

###########################################################################

[Script:Counters]
#GVAR = RunAfter:999 IfFunction:global_var,set_global_var DoArgumentCount:0,GVAR
#AllFunctions = RunAfter:999 IfFunction DoNameCount:AllFunctions

[Script:Detect]
#
# gender
#
Gender:Crit = RunAfter:9999 IfVariable:get_gender,dude_gender,self_gender IfOperator DoLogCurrentLine:DEBUG
Gender:GetCritterStat = RunAfter:9999 IfFunction:get_critter_stat IfArgumentIs:1,STAT_gender DoLogCurrentLine:DEBUG
#
# misc
#
#AttackComplex = RunAfter:9999 IfFunction:attack_complex DoLogCurrentLine
#CurMapIndexEquals = RunAfter:9999 IfVariable:cur_map_index IfOperatorName:Equals DoLogCurrentLine
#GetCritterStat = RunAfter:9999 IfFunction:get_critter_stat DoLogCurrentLine
Metarule = RunAfter:9999 IfFunction:metarule,metarule2,metarule2_explosions,metarule3 DoLogCurrentLine
#NotWithOneArg = RunAfter:9999 IfFunction:not IfArgumentsSize:1 IfNotEdited DoLogCurrentLine
RandomD6 = RunAfter:9999 IfFunction:random IfArgumentValue:0,1 IfArgumentValue:1,6 IfOperator DoLogCurrentLine
RandomWasting = RunAfter:9999 IfFunction:random IfArgumentsEqual:0,1 DoLogCurrentLine
RegAnimFunc = RunAfter:9999 IfFunction:reg_anim_func DoLogCurrentLine
#ScriptAction = RunAfter:9999 IfVariable:script_action DoFileCount:script_action
SfallFunc = RunAfter:9999 IfFunction:sfall_func0,sfall_func1,sfall_func2,sfall_func3,sfall_func4,sfall_func5,sfall_func6 DoLogCurrentLine
#SCRIPT_MODREACT = RunAfter:9999 IfFunction:giq_option IfArgumentIs:1,SCRIPT_MODREACT IfNotEdited DoLogCurrentLine
#SCRIPT_GENCHAT =  RunAfter:9999 IfFunction:giq_option IfArgumentIs:1,SCRIPT_GENCHAT IfNotEdited DoLogCurrentLine
#TileContainsPidObj:BlockingHex = RunAfter:9999 IfFunction:tile_contains_pid_obj IfArgumentIs:2,PID_BLOCKING_HEX DoLogCurrentLine
WorldmapTerrain = RunAfter:9999 IfFunction:global_var IfArgumentIs:0,GVAR_WORLDMAP_TERRAIN IfOperator DoLogCurrentLine
ReadX = RunAfter:9999 IfFunction:read_byte,read_short,read_int,read_string DoLogCurrentLine
WriteX = RunAfter:9999 IfFunction:write_byte,write_short,write_int,write_string DoLogCurrentLine

[Script:Experimental]
SkillSuccess = RunAfter IfFunction:is_success IfArgumentCondition:0,Experimental,SkillSuccess.Helper DoArgumentResult:0,Experimental,SkillSuccess.Helper DoNameSet:skill_success DoArgumentSetCached:0,arg0 DoArgumentsPushBackCached:arg1 DoArgumentsPushBackCached:arg2
SkillSuccess.Helper = RunOnDemand IfFunction:roll_vs_skill DoArgumentCache:0,arg0 DoArgumentCache:1,arg1 DoArgumentCache:2,arg2
DudeSkillSuccess = RunAfter:105 IfFunction:skill_success IfArgumentValue:0,dude_obj DoNameSet:dude_skill_success DoArgumentsErase:0

StatSuccess = RunAfter IfFunction:is_success IfArgumentCondition:0,Experimental,StatSuccess.Helper DoArgumentResult:0,Experimental,StatSuccess.Helper DoNameSet:stat_success DoArgumentSetCached:0,arg0 DoArgumentsPushBackCached:arg1 DoArgumentsPushBackCached:arg2
StatSuccess.Helper = RunOnDemand IfFunction:do_check DoArgumentCache:0,arg0 DoArgumentCache:1,arg1 DoArgumentCache:2,arg2
DudeStatSuccess = RunAfter:105 IfFunction:stat_success IfArgumentValue:0,dude_obj DoNameSet:dude_stat_success DoArgumentsErase:0
